import random
class Role(object):
    def __init__(self, name, sex, blood=100,equipment="suit"):
        self.name = name
        self.sex = sex
        self.blood = blood
        self.equipment = equipment
        self.room = None
    def attach(self, other):
        fight = {5: "正常攻击", 10: "增强攻击"}
        if self == other:
            print("不能攻击自己")
        else:
            if self.room and self.room == other.room:
                if self.blood <= 0:
                    print("你的血量低于0，不能进行攻击")
                else:
                    if random.choice([0,1]):
                        lost_blood = 5
                    else:
                        lost_blood = 10
                    other.blood = other.blood - lost_blood
                    print(f"{self.name}使用{fight[lost_blood]}{other.name}掉{lost_blood}点血,当前血量{other.blood}")
                    if other.blood <= 0:
                        print(f"{other.name}没有血量了")
                        exit()
            else:
                print("双方不在同一个房间不能进行攻击")


class Room(object):
    def __init__(self, name):
        self.name = name
        self.member_list = []

    def add_member(self, role):
        if role.room == None:
            if len(self.member_list) < 2:
                self.member_list.append(role)
                role.room = self
                print(f"{role.name}成功加入{self.name}房间")
            else:
                print(f"{role}已加入{role.room.name}")


print('''####################
      1、创建角色
      2、创建房间
      3、加入房间
      4、开始战斗
      5、退出
####################''')
roles = dict()
rooms = dict()
while True:
    number = input("请输入你的操作: \n")
    option = int(number)
    if 1 <= option <= 5:
        if option == 1:
            name, sex = input("请输入角色的姓名与性别，使用空格间隔: \n").split()
            roles[name] = Role(name, sex)
        elif option == 2:
            room = input("请输入房间的名字: \n")
            rooms[room] = Room(room)
        elif option == 3:
            print(f"当前角色有{roles.keys()},当前房间有{rooms.keys()}")
            role_name, room_name = input("请输入你要加入的角色和房间名，使用空格间隔: \n").split()
            rooms[room_name].add_member(roles[role_name])
        elif option == 4:
            while True:
                enter = random.choice([0, 1])
                if enter == 0:
                    rooms[room_name].member_list[0].attach(rooms[room_name].member_list[1])
                else:
                    rooms[room_name].member_list[1].attach(rooms[room_name].member_list[0])
    else:
        print("输入错误，请重新输入1-5选项")
